<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/style.css" rel="stylesheet">
</head>

<body>
    <script>
        function getFlagArrs() {
            let m = 5
            let n = 3
            // if (!n || n < 1) {
            //     return []
            // }

            let resultArrs = []
            let flagArr = []
            let isEnd = false
            let i, j, leftCnt

            for (i = 0; i < m; i++) {
                flagArr[i] = i < n ? 1 : 0
            }

            resultArrs.push(flagArr.concat())

            while (!isEnd) {
                leftCnt = 0
                for (i = 0; i < m - 1; i++) {
                    if (flagArr[i] === 1 && flagArr[i + 1] === 0) {
                        for (j = 0; j < i; j++) {
                            flagArr[j] = j < leftCnt ? 1 : 0
                        }
                        flagArr[i] = 0
                        flagArr[i + 1] = 1
                        var aTmp = flagArr.concat()
                        resultArrs.push(aTmp)
                        if (aTmp.slice(-n).join('').indexOf('0') === -1) {
                            isEnd = true
                        }
                        break
                    }
                    flagArr[i] === 1 && leftCnt++
                }
            }
            // console.log(resultArrs)
            // 根据这个排列组合计算总分
            let P = [89, 38]
            let A = [445, 754]
            let res = 0
            for (let i = 0; i < resultArrs.length; i++) {
                let sum = 0
                for (let j = 0; j < m; j++) {
                    if (resultArrs[i][j] == 1) {
                        sum += resultArrs[i][j] * A[j]
                    } else {
                        sum += P[j] * A[j] / 100
                    }
                }
                res = Math.max(sum, res)
            }
            console.log(res.toFixed(2))
            return res;
        }
        getFlagArrs()
    </script>
</body>

</html>